#include <stdio.h>
#include "../libpcap/libpcap.h"

int fn_calc_crc(unsigned int no, unsigned char *buffer, unsigned int size)
{
    unsigned int crc_val = 0;

    if (size < READIO_HDR_SIZE + 4) {
        printf("line:%d, error frame!\n", no);
        return 0;
    }

    crc_val = pcap_calc_crc32(0, buffer + READIO_HDR_SIZE, size - READIO_HDR_SIZE - 4);
    printf("line:%d, crc:%08X\n", no, crc_val);
    return 0;
}

int main(int argc, char *argv[])
{
    PCAP_HANDLE handle = NULL;
    if (argc != 2) {
        printf("usage pcap-crc [pcap file]\n");
        return 0;
    }

    handle = pcap_open(argv[1]);
    pcap_for_each_frame(handle, fn_calc_crc);
    pcap_close(handle);
    return 0;
}
